trait Person {
    fn name(&self) -> String;
}

// Person 是 Student 的父 trait。
// 实现 Student 需要你也 impl 了 Person。
trait Student: Person {
    fn university(&self) -> String;
}

trait Programmer {
    fn fav_language(&self) -> String;
}

// CompSciStudent (computer science student，计算机科学的学生) 是 Programmer 和 Student 两者的子类。
// 实现 CompSciStudent 需要你同时 impl 了两个父 trait。
trait CompSciStudent: Programmer + Student {
    fn git_username(&self) -> String;
}

fn comp_sci_student_greeting(student: &dyn CompSciStudent) -> String {
    format!(
        "My name is {} and I attend {}. My favorite language is {}. My Git username is {}",
        student.name(),
        student.university(),
        student.fav_language(),
        student.git_username()
    )
}

struct UPKSciStudent {
    name: String,
    language: String,
    git_username: String,
}

impl CompSciStudent for UPKSciStudent {
    fn git_username(&self) -> String {
        self.git_username.clone()
    }
}

impl Person for UPKSciStudent {
    fn name(&self) -> String {
        self.name.clone()
    }
}

impl Programmer for UPKSciStudent {
    fn fav_language(&self) -> String {
        self.language.clone()
    }
}

impl Student for UPKSciStudent {
    fn university(&self) -> String {
        "upk".to_string()
    }
}

#[test]
fn main() {
    let stu = UPKSciStudent { name: "hei".to_string(), language: "rust".to_string(), git_username: "hei@upk.org".to_string() };
    println!("{}", comp_sci_student_greeting(&stu));
}
